package com.ruoyi.web.controller.smsPurchase;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.util.StoreIdUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SmsPurchase;
import com.ruoyi.system.service.ISmsPurchaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 购买短信 Controller
 *
 * @author ruoyi
 * @date 2025-05-07
 */
@Api(tags="购买短信")
@RestController
@RequestMapping("/system/smsPurchase")
public class SmsPurchaseController extends BaseController
{
    @Autowired
    private ISmsPurchaseService smsPurchaseService;

    @Autowired
    private StoreIdUtils storeIdUtils;

    /**
     * 查询购买短信列表
     */
    @ApiOperation("查询购买短信列表")
    @PreAuthorize("@ss.hasPermi('system:purchase:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsPurchase smsPurchase)
    {
        startPage();
//        smsPurchase.setId(storeIdUtils.getStoreId());
        List<SmsPurchase> list = smsPurchaseService.selectSmsPurchaseList(smsPurchase);
        return getDataTable(list);
    }

    /**
     * 导出购买短信列表
     */
    @ApiOperation("导出购买短信列表")
    @PreAuthorize("@ss.hasPermi('system:purchase:export')")
    @Log(title = "购买短信", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmsPurchase smsPurchase)
    {
//        smsPurchase.setId(storeIdUtils.getStoreId());
        List<SmsPurchase> list = smsPurchaseService.selectSmsPurchaseList(smsPurchase);
        ExcelUtil<SmsPurchase> util = new ExcelUtil<SmsPurchase>(SmsPurchase.class);
        util.exportExcel(response,list, "购买短信数据");
    }

    /**
     * 通过id获取购买短信详细信息
     */
    @ApiOperation("通过id获取购买短信详细信息")
    @PreAuthorize("@ss.hasPermi('system:purchase:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(smsPurchaseService.selectSmsPurchaseById(id));
    }

    /**
     * 新增购买短信
     */
    @ApiOperation("新增购买短信")
    @PreAuthorize("@ss.hasPermi('system:purchase:add')")
    @Log(title = "购买短信", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmsPurchase smsPurchase)
    {
//        smsPurchase.setId(storeIdUtils.getStoreId());
        return toAjax(smsPurchaseService.insertSmsPurchase(smsPurchase));
    }

    /**
     * 修改购买短信
     */
    @ApiOperation("修改购买短信")
    @PreAuthorize("@ss.hasPermi('system:purchase:edit')")
    @Log(title = "购买短信", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmsPurchase smsPurchase)
    {
//        smsPurchase.setId(storeIdUtils.getStoreId());
        return toAjax(smsPurchaseService.updateSmsPurchase(smsPurchase));
    }


    /**
     * 通过id批量删除购买短信信息
     */
    @ApiOperation("通过id批量删除购买短信信息")
    @PreAuthorize("@ss.hasPermi('system:purchase:remove')")
    @Log(title = "购买短信", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsPurchaseService.deleteSmsPurchaseByIds(ids));
    }

    /**
     * 通过id修改签名内容
     */
    @ApiOperation("通过id修改签名内容")
    @PreAuthorize("@ss.hasPermi('system:purchase:edit')")
    @Log(title = "购买短信 - 修改签名内容", businessType = BusinessType.UPDATE)
    @PutMapping("/updateSignature/{id}")
    public AjaxResult updateSignatureContent(
            @PathVariable("id") Long id,
            @RequestBody Map<String, String> updateData)
    {
        if (!updateData.containsKey("signatureContent")) {
            return AjaxResult.error("缺少签名内容参数");
        }
        return toAjax(smsPurchaseService.updateSignatureContentById(
                id, updateData.get("signatureContent")));
    }


}

